package com.sanji.sjmallmodule.login;

import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.sanji.sjmallapp.BaseActivity;
import com.sanji.sjmallapp.R;
import com.sanji.sjmallconfig.ConfigAPI;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/7/18.
 */

public class UrlEditActivity extends BaseActivity implements View.OnClickListener{

    @BindView(R.id.common_title_tv)
    TextView titleTv;
    @BindView(R.id.url_edit_original)
    TextView originalText;
    @BindView(R.id.url_edit_new)
    EditText newEdit;

    private String originalUrl;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_url_edit);
        ButterKnife.bind(this);
        initViews();
    }

    private void initViews(){
        titleTv.setText("地址修改");

        findViewById(R.id.common_back_img).setOnClickListener(this);
        findViewById(R.id.url_edit_submit).setOnClickListener(this);

        originalUrl = myShare.getString("BASE_URL", ConfigAPI.BASE_URL);
        originalText.setText(originalUrl);
        newEdit.setText(originalUrl);

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.common_back_img:
                finishActivity();
                break;
            case R.id.url_edit_submit:
                String newUrl = newEdit.getText().toString().trim();
                if (!"".equals(newUrl) && !newUrl.equals(originalUrl)){
                    //新地址有修改
                    ConfigAPI.setAbsoluteUrl(newUrl);
                    finishActivity();
                }

                break;
        }
    }
}
